fix(react-doctor): skip empty patterns before knip runs (#149)#150
Draft
fix(react-doctor): skip empty patterns before knip runs (#149)#150
Conversation
knip funnels every entry/project/ignore pattern through picomatch, which throws 'Expected pattern to be a non-empty string' if any value is empty or whitespace-only. Empty patterns can sneak in via tsconfig include, plugin shorthand resolution, or hand-written knip.json entries — knocking out the entire dead-code step. runKnip now walks the parsed knip config (top-level keys, nested plugin objects, per-workspace overrides) and removes empty / whitespace-only string patterns — both as scalars and as entries inside arrays — before invoking knip's main(). Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #149.
Problem
react-doctorreports× Dead code detection failed (non-fatal, skipping). Expected pattern to be a non-empty stringand silently drops the entire dead-code step.The error originates inside
knip: every entry, project, ignore, and plugin pattern is funneled throughpicomatch, which throwsTypeError: Expected pattern to be a non-empty stringif any value is""or whitespace-only. Empty entries can sneak in via:tsconfig.jsoninclude/excludeknip.jsonentriespackage.jsonmain/exportsfieldsA single bad entry takes down all dead-code analysis instead of being skipped.
Fix
runKnipnow sanitizes the parsed knip config before callingmain():The bad pattern is removed; everything else still runs.
Tests
tests/sanitize-knip-config-patterns.test.ts— 7 unit tests covering scalars, arrays, nested plugin/workspace configs, regex preservation, and falsy non-string passthroughtests/run-knip.test.ts— new case verifying the sanitizer runs aftercreateOptionsand before the firstmain()invocationtests/regressions/scan-resilience.test.ts— issue [Bug]: Expected pattern to be a non-empty string #149 added to the registry of pipeline-resilience invariantsAll 457 existing tests still pass;
pnpm typecheckandpnpm lintare clean for the changed files.Files
packages/react-doctor/src/utils/sanitize-knip-config-patterns.ts(new)packages/react-doctor/src/utils/run-knip.ts(wires the sanitizer in)packages/react-doctor/tests/sanitize-knip-config-patterns.test.ts(new)packages/react-doctor/tests/run-knip.test.tspackages/react-doctor/tests/regressions/scan-resilience.test.ts.changeset/issue-149-empty-pattern-knip.md